<?php
// 信息列表
namespace app\shop\controller;

use think\Db;
use think\Request;
use think\Session;
use think\Controller;
use app\shop\model\Member as MemberModel;
use app\shop\model\Information as InformationModel;
use app\shop\model\MemberMessage as MemberMessageModel;

class Message extends Controller
{
    /**
     * 消息列表
     */
    public function index()
    {
        // 获取参数
        $user_id = Session::get('member_id');
        $model = new MemberMessageModel();
        $create_time = (new MemberModel())->where('id', $user_id)->value('create_time');
        // 验证数据
        $str = $user_id . ',' . '0';
        $condition['member_id'] = ['in', $str];
        $condition['create_time'] = ['gt', $create_time];
        $result = $model->where($condition)->field('id,title,content,create_time')->order('create_time', 'desc')->paginate(15);

        foreach ($result as &$value) {
            $value['content'] = strip_tags($value['content']);
        }


        return $this->fetch('', [
            'mate_head' => '信息中心',
            'data'      => $result
        ]);


    }


    public function detail()
    {
        // 信息ID
        $id = Request::instance()->param('mid');

        $model = new MemberMessageModel();

        $item = $model->where('id', $id)->find();


        return $this->fetch('', [
            'mate_head' => "消息详情",
            'item'      => $item
        ]);


    }


    public function information()
    {
        $id = Request::instance()->param('id');

        $item = (new InformationModel())->where('parenTid',$id)->find();
        Db::name('information')->where('id',$item['id'])->setInc('hit');

        return $this->fetch('',[
            'mate_head' => $item['title'],
            'item'      => $item,
        ]);
    }
}